#include<bits/stdc++.h>
using namespace std;
int T,n,a[200001],maxs=0;
int dfs(int score,int num,int bn,int rn){
    maxs=max(maxs,score);
    if(num>0){
        if(a[num-1]==rn){
            dfs(score+rn,num-1,bn,0);
        }else{
            dfs(score,num-1,bn,a[num-1]);
        }
        if(a[num-1]==bn){
            dfs(score+bn,num-1,0,rn);
        }else{
            dfs(score,num-1,a[num-1],rn);
        }
    }
    return maxs;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    for(int i=1;i<=T;i++){
        cin>>n;
        for(int j=1;j<=n;j++){
            cin>>a[j];
        }
        cout<<dfs(0,n,0,a[n])<<endl;
        maxs=0;
    }
    return 0;
}
